package com.jz.lkx.ui.custom_view.dialog

import android.content.Context
import android.os.Bundle
import android.widget.Button
import android.widget.ProgressBar
import android.widget.TextView
import pri.jz.keeper.R
import pri.jz.keeper.jui.jdialog.JBaseDialog

/**
 *Author by: JZ
 *Email: 2451756617@qq.com
 *PS: 文件下载
 */
class JProgressDialog(context: Context): JBaseDialog(context){
    private lateinit var progressBar: ProgressBar
    private lateinit var nowProgressText: TextView
    private lateinit var totalProgressText: TextView
    private lateinit var btn: Button
    private var btnClick: () -> Unit = {}

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.layout_progress_dialog)
        initView()
    }

    private fun initView() {
        progressBar = findViewById<ProgressBar?>(R.id.update_dialog_progress).apply {
            max = 100
            progress = 50
        }
        nowProgressText = findViewById(R.id.update_dialog_now_progress)
        totalProgressText = findViewById(R.id.update_dialog_total_progress)
        btn = findViewById<Button?>(R.id.update_dialog_btn).apply {
            setOnClickListener { btnClick() }
        }
    }
    //进度条设置
    fun setTotalProgress(totalProgress: Int) {
        progressBar.max = totalProgress
        totalProgressText.text = totalProgress.toString()
    }
    fun getTotalProgress(): Int = progressBar.max

    fun setNowProgress(progress: Int) {
        progressBar.progress = progress
    }
    fun getNowProgress(): Int = progressBar.progress
    //进度指示框文本设置
    fun setProgressText(progressText: String) {
        nowProgressText.text = progressText
    }
    fun setTotalProgressText(totalProgressText: String) {
        this.totalProgressText.text = totalProgressText
    }

    //按钮设置
    fun setBtnClick(btnClick: () -> Unit) {this.btnClick = btnClick}
    fun setBtnText(btnText: String) {btn.text = btnText}
}